home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_075 / speeddir / src / speeddir.asm < prev   
Assembly Source File  |  1992-05-06  |  10KB  |  441 lines

  1. ;
  2. ; Speeddir By Bryce Nesbitt. 
  3. ; Disclaimer: Guaranteed defective.  If it works, lucky you!  If you improve
  4. ;  on it please send a copy back to the author at:
  5. ;  1712 Marin Ave.  Berkeley, Ca 94707-2206.  bryce@cogsci.Berkeley.EDU
  6. ;
  7.  NOLIST
  8.  INCLUDE 'exec/types.i'
  9.  INCLUDE 'exec/memory.i'
  10.  INCLUDE 'exec/ports.i'     ;lots of stuff
  11.  INCLUDE 'exec/io.i'
  12.  INCLUDE 'libraries/dos.i'
  13.  INCLUDE 'libraries/dosextens.i'
  14.  INCLUDE 'devices/trackdisk.i'
  15. ;INCLUDE 'lib/exec_lib.i'   ;You don't have these.  So *you*
  16. ;INCLUDE 'lib/dos_lib.i'    ;need bother with the linker. :-)
  17. blink macro
  18.  move.l d7,-(a7)
  19.  move.b $bfe001,d7
  20.  eori.b #2,d7
  21.  move.b d7,$bfe001
  22.  move.l (a7)+,d7
  23.  endm
  24. jsrlib MACRO
  25.  xref _LVO\1
  26.  jsr _LVO\1(a6)
  27.  ENDM
  28. jmplib MACRO    
  29.  xref _LVO\1
  30.  jmp _LVO\1(a6)
  31.  ENDM
  32.  LIST
  33. *******************************
  34. DEBUG    equ 1
  35.     NOLIST
  36.     INCLUDE 'libraries/filehandler.i'
  37.     LIST
  38. **************************
  39. DOS_TRUE    equ 0
  40. DOS_FALSE    equ -1
  41. myprocport    equr a5
  42. packet        equr a4
  43.  
  44. ;--Get ready...--
  45.         move.l    4,a6
  46.         lea    DOSName(pc),a1
  47.         jsrlib    OldOpenLibrary
  48.         move.l    d0,a6
  49.         move.l    d0,a5
  50.         lea    Volume,a0
  51.         move.l    a0,d1
  52.         jsrlib    DeviceProc
  53.         tst.l    d0
  54.         beq    noway
  55.         move.l    d0,a4
  56.         lea    MyWait,a0
  57.         move.l    a0,pr_PktWait-TC_SIZE(a4)
  58.         move.l    4,a6
  59. lplplp        ;move.l  #SIGBREAKF_CTRL_C,d0
  60.         moveq    #0,d0
  61.         jsrlib    Wait
  62.         ;jsrlib  Forbid
  63.         ;clr.l     pr_PktWait-TC_SIZE(a4)
  64.         ;move.l  a5,a6
  65.         ;move.l  #150,d1
  66.         ;jsrlib  Delay
  67.         ;move.l  4,a6
  68.         ;jsrlib  Permit
  69. noway        moveq    #21,d0
  70.         rts
  71. ;
  72. ;DOSpacket=GETAPACKETE()
  73. ;a0
  74. ;Waits for then gets a packet
  75. ;
  76. MyWait        movem.l a2/a6,-(a7)
  77. MyWaitLp    move.l    4,a6
  78.         suba.l    a1,a1
  79.         jsrlib    FindTask
  80.         add.l    #TC_SIZE,d0
  81.         move.l    d0,a0
  82.         move.l    d0,a2
  83.         jsrlib    WaitPort ;!!Signal 8??
  84.         move.l    a2,a0
  85.         jsrlib    GetMsg
  86.         move.l    d0,a0
  87.  
  88.         move.l    LN_NAME(a0),a1
  89.         move.l    a2,a0
  90.         cmp.w    #$18,dp_Type+2(a1)
  91.         beq.s    ExTheNext
  92.         movem.l (a7)+,a2/a6
  93.         rts
  94. *******************************
  95. ;
  96. ;success=ExNext(lock,FileInfoBlock)
  97. ;d0        d1   d2
  98. ;
  99. fib_KOB     equ  fib_FileName+96    ;* Kludge-O-Buffer
  100. fib_HashChain    equ  fib_FileName+100    ;* Where to chain to
  101. fib_ChainRoot    equ  fib_FileName+104    ;* Where chain started from
  102. HASHSIZE    equ  72
  103. KOB_SIZE    equ  HASHSIZE*4
  104. ST.USERDIR    equ  2
  105. ST.FILE     equ  -3
  106. ST.ROOT     equ  1
  107. T.SHORT     equ  2
  108. T.LIST        equ  16
  109. T.DATA        equ  8
  110. exfib        equr a4
  111. blockbuffer    equr a3
  112.  
  113. ;--We can do the job--
  114. ExTheNext    movem.l (a7)+,a2/a6
  115.         movem.l d2-d3/a0-a4/a6,-(a7)
  116.         move.l    4,a6
  117.         move.l    dp_Arg2(a1),d0
  118.         asl.l    #2,d0
  119.         move.l    d0,exfib
  120.         move.l    #512,d0
  121.         move.l    #MEMF_CLEAR+MEMF_CHIP,d1
  122.         jsrlib    AllocMem
  123.         tst.l    d0        ;grrr...
  124.         beq    e_memory
  125.         move.l    d0,blockbuffer
  126. ;--Check if this is the first time 'round--
  127.         btst    #7,fib_Protection(exfib)  ;!!Byte test!!
  128.         bne.s    exthenext
  129. ;--This is a new request. Allocate some kludg-o ram--
  130.         move.l    #KOB_SIZE,d0
  131.         move.l    #MEMF_PUBLIC+MEMF_CLEAR,d1
  132.         jsrlib    AllocMem
  133.         move.l    d0,fib_KOB(exfib)
  134.         beq    e_memory
  135.         clr.l    fib_HashChain(exfib)
  136.         clr.l    fib_ChainRoot(exfib)
  137.         move.l    (exfib),d0    ;fib_DiskKey
  138.         move.l    blockbuffer,a0
  139.         bsr    READBLOCK
  140.         cmp.l    #T.SHORT,(blockbuffer)
  141.         bne    e_errorreading
  142.         moveq    #HASHSIZE-1,d0
  143.         move.l    blockbuffer,a0
  144.         adda.l    #24,a0
  145.         move.l    fib_KOB(exfib),a1
  146. KOBfill     move.l    (a0)+,(a1)+
  147.         dbra    d0,KOBfill
  148.         clr.l    (exfib)
  149. ;--Check if we should chain--
  150. exthenext    tst.l    fib_KOB(exfib)    ;This time they simply
  151.         beq    e_endagain    ;went too far...
  152.         move.l    fib_HashChain(exfib),d0
  153.         bne.s    getit        ;Follow the chain
  154. ;--Derive next block from hash table--
  155. ScanList    moveq    #-1,d0
  156.         moveq    #-1,d1
  157.         move.l    fib_ChainRoot(exfib),d2 ;fib_DiskKey
  158.         moveq    #71,d3
  159.         move.l    fib_KOB(exfib),a0
  160.  
  161. scanlp        ;move.l  d0,-(a7)
  162.         ;move.l  d3,d0
  163.         ;bsr     PRINTLONGHEX
  164.         ;move.l  (a7)+,d0
  165.         cmp.l    (a0)+,d2
  166.         dbcs    d3,scanlp    ;Until end or d0 is LOWER
  167.         bcc.s    endscan
  168.         move.l    -4(a0),a1
  169.         cmp.l    a1,d0        ;compare with last try
  170.         bls.s    far        ;new one is farther
  171.         moveq    #0,d1
  172.         move.l    a1,d0
  173.            ;bsr    PRINTLONGHEX
  174. far        dbra    d3,scanlp    ;DBCS does not decrement count
  175.  
  176. endscan     tst.l    d1
  177.         bmi    e_nomore
  178. ;--Got it, so get it--
  179. getit        ;[block in d0]
  180.         ;bsr     PRINTLONGHEX
  181.         move.l    blockbuffer,a0
  182.         bsr    READBLOCK
  183.         bmi    e_memory
  184.         bne    e_errorreading
  185. ;--Valid User Directory in (blockbuffer). Fill in exfib--
  186.         move.l    fib_HashChain(exfib),d0
  187.         move.l    512-16(blockbuffer),fib_HashChain(exfib)
  188.         tst.l    d0
  189.         bne.s    thisisachain
  190.         move.l    4(blockbuffer),fib_ChainRoot(exfib)
  191. thisisachain    move.l    4(blockbuffer),(exfib)    ;fib_DiskKey
  192.         ;compare with expected
  193.         ;compare type
  194.         moveq    #ST.USERDIR,d1
  195.         move.l    512-4(blockbuffer),d0    ;Secondary type
  196.         cmp.l    d0,d1
  197.         beq.s    STValid
  198.         moveq    #ST.FILE,d1
  199.         cmp.l    d0,d1
  200.         bne    e_errorreading
  201. STValid     move.l    d1,fib_DirEntryType(exfib)
  202. ;--Filename-- -80
  203.         lea    fib_FileName(exfib),a1
  204.         lea    512-80(blockbuffer),a0
  205.         moveq    #0,d0        ;Clear upper half
  206.         move.b    (a0)+,d0
  207.         move.b    d0,(a1)+
  208.            ; beq.s     noname
  209.            ; subq.w  #1,d0         ;Compensate for dbra
  210. loop1        move.b    (a0)+,(a1)+
  211.         dbra    d0,loop1    ;68010 Loop mode
  212. noname           ; clr.b     (a1)         ;Null terminate string
  213. ;--Protection bits-- -192
  214.         move.l    512-192(blockbuffer),d0
  215.         bset    #31,d0        ;Set we've been here flag
  216.         move.l    d0,fib_Protection(exfib)
  217. ;--Size in bytes-- -188
  218.         move.l    512-188(blockbuffer),d0
  219.         move.l    d0,fib_Size(exfib)
  220.         beq.s    zeroblocks
  221. ;--Calculate # blocks in file--
  222. ;--Do *NOT* read in list blocks from disk!--
  223. ;$1E7FE18/$1E8=$FFFF
  224.         divu    #488,d0 ;!!Ok for files <= 31981080 bytes long
  225.         trapv
  226.         move.w    d0,d1
  227.         ext.l    d0    ;extend result
  228.         swap    d1
  229.         tst.w    d1        ;Test remainder
  230.         beq.s    zeroblocks    ;Even multiply
  231.         addq.l    #1,d0        ;Tweak block count
  232.         ;nop
  233. zeroblocks    move.l    d0,fib_NumBlocks(exfib)
  234. ;--DateStamp-- -92
  235.         lea    512-92(blockbuffer),a0
  236.         lea    fib_DateStamp(exfib),a1
  237.         move.l    (a0)+,(a1)+
  238.         move.l    (a0)+,(a1)+
  239.         move.l    (a0)+,(a1)+
  240. ;--Comment-- 184
  241.         lea    fib_Comment(exfib),a1
  242.         lea    512-184(blockbuffer),a0
  243.         moveq    #0,d0        ;Clear upper part
  244.         move.b    (a0)+,d0
  245.         move.b    d0,(a1)+
  246.            ; beq.s     nocomment
  247.            ; subq.w  #1,d0         ;Compensate for dbra
  248. loop2        move.b    (a0)+,(a1)+
  249.         dbra    d0,loop2
  250. nocomment      ; clr.b     (a1)
  251. ;--Exit ok--
  252.         suba.l    a2,a2
  253.         bra.s    ExitA2
  254. e_errorreading    move.w    #ERROR_SEEK_ERROR,a2
  255.         bra.s    ExitA2
  256. e_memory    move.w    #ERROR_NO_FREE_STORE,a2
  257.         bra.s    ExitA2
  258. e_nomore    move.l    fib_KOB(exfib),a1
  259.         move.l    #KOB_SIZE,d0
  260.         jsrlib    FreeMem
  261. e_endagain    move.w    #ERROR_NO_MORE_ENTRIES,a2
  262. ExitA2        move.l    #512,d0
  263.         move.l    blockbuffer,a1
  264.         jsrlib    FreeMem
  265. ;--Place error code in d0 where IOErr can find it--
  266.         suba.l    a1,a1
  267.         jsrlib    FindTask
  268.         move.l    d0,a0
  269.         move.l    a2,pr_Result2(a0)
  270.         move.l    a2,d1
  271.         movem.l (a7)+,d2-d3/a0-a4/a6
  272.         bne.s    anerror
  273.         moveq    #-1,d0
  274.         bra.s    noerror
  275. anerror     moveq    #0,d0
  276. ;== Return the packet ==
  277. noerror     movem.l a2/a6,-(a7)
  278.         blink
  279.         move.l    4,a6
  280.         move.l    d0,dp_Res1(a1)
  281.         move.l    d1,dp_Res2(a1)
  282.         move.l    dp_Port(a1),d0
  283.         move.l    a0,dp_Port(a1)
  284.         move.l    dp_Link(a1),a1
  285.         move.l    d0,a0
  286.         jsrlib    PutMsg
  287.         bra    MyWaitLp
  288. ;--------------------------------
  289. ;
  290. ;PRINTLONGHEX(value)
  291. ;          d0
  292. ;
  293.         ifeq    1
  294. PRINTLONGHEX    movem.l d0-d3/a0-a1/a6,-(a7)
  295.         subq.l    #5,a7    ;Take 10 bytes from stack
  296.         subq.l    #5,a7    ;(it's smaller...)
  297.         move.l    a7,a0
  298.         moveq    #7,d2
  299.  
  300. hexlp        rol.l    #4,d0
  301.         move.l    d0,d1
  302.         andi.w    #$f,d1
  303.         move.b    hextab2(pc,d1.w),(a0)+
  304.         dbra    d2,hexlp
  305.  
  306.         move.b    #10,(a0)
  307.         move.b    #32,(a0)
  308.         move.l    4,a6
  309.         lea    DOSName,a1
  310.         jsrlib    OldOpenLibrary    ;V1.0 compatible :-)
  311.         tst.l    d0        ;grrr...
  312.         beq.s    er_lib
  313.         move.l    d0,a6
  314.         jsrlib    Output
  315.         move.l    d0,d1
  316.         beq.s    er_output
  317.         move.l    a7,d2
  318.         moveq    #9,d3
  319.         jsrlib    Write        ;skip error check
  320.         move.l    a6,a1
  321.         move.l    4,a6
  322.         jsrlib    CloseLibrary
  323.         addq.l    #5,a7
  324.         addq.l    #5,a7
  325. er_output
  326. er_lib        movem.l (a7)+,d0-d3/a0-a1/a6
  327.         rts
  328. hextab2     dc.b    '0123456789ABCDEF'
  329.         endc
  330. ;
  331. ; port=CREATEPORTE(),exec
  332. ; d0             a6
  333. ; z=error
  334. ;
  335. ;FUNCTION: Create a nameless message port, 0 priority.
  336. ;RESULT: The port pointer or Z=1 if an error occured.
  337. ;REGISTERS: A6 must contain exec!
  338. ;EXAMPLE:    bsr    CREATEPORTE
  339. ;        beq.s    noport    ;Not enough memory (or signals)
  340. ;
  341.         ;xref    CREATEPORTE
  342. CREATEPORTE    move.l    a2,-(a7)
  343.         move.l    #MEMF_PUBLIC+MEMF_CLEAR,d1
  344.         moveq    #MP_SIZE,d0
  345.         jsrlib    AllocMem
  346.         move.l    d0,a2
  347.         tst.l    d0
  348.         beq.s    cp_nomemory
  349.         moveq    #-1,d0
  350.         jsrlib    AllocSignal    ;d0=return
  351.         moveq    #-1,d1
  352.         cmp.l    d0,d1    ;-1 indicates bad signal
  353.         bne.s    cp_sigok
  354.         move.l    a2,a1
  355.         moveq    #MP_SIZE,d0
  356.         jsrlib    FreeMem
  357. cp_nomemory    move.l    (a7)+,a2
  358.         moveq    #0,d0
  359.         rts
  360.  
  361. cp_sigok    move.b    d0,MP_SIGBIT(a2)
  362.         move.b    #PA_SIGNAL,MP_FLAGS(a2)
  363.         move.b    #NT_MSGPORT,LN_TYPE(a2)
  364.         clr.b    LN_PRI(a2)
  365.         suba.l    a1,a1           ;a1=0/Find this task
  366.         jsrlib    FindTask       ;[d0=this task]
  367.         move.l    d0,MP_SIGTASK(a2)
  368.         lea    MP_MSGLIST(a2),a0  ;Point to list header
  369.         NEWLIST a0        ;Init new list macro
  370.         move.l    a2,d0
  371.         move.l    (a7)+,a2    ;cc's NOT affected
  372.         rts
  373. ;
  374. ;DELETEPORTE(port),exec
  375. ;         a1    a6
  376. ;
  377. ;FUNCTION:  Deletes the port by first setting some
  378. ; fields to illegal values then calling FreeMem.
  379. ;RESULT: none
  380. ;REGISTERS: A6 must contain exec!
  381. ;
  382.         ;xref    DELETEPORTE
  383. DELETEPORTE    move.l    a1,-(a7)
  384.         moveq    #-1,d0
  385.         move.b    d0,LN_TYPE(a1)
  386.         move.l    d0,MP_MSGLIST+LH_HEAD(a1)
  387.         moveq    #0,d0    ;Clear upper 3/4 of d0
  388.         move.b    MP_SIGBIT(a1),d0
  389.         jsrlib    FreeSignal
  390.         move.l    (a7)+,a1
  391.         moveq    #MP_SIZE,d0
  392.         jmplib    FreeMem
  393. ;
  394. ;READBLOCK(buffer,block)
  395. ;       a0      d0
  396. ;
  397. READBLOCK    movem.l d2/a3/a6,-(a7)
  398.         move.l    4,a6
  399.         move.l    d0,d2
  400.         move.l    a0,a3
  401.         suba.l    #IOTD_SIZE,a7
  402.         moveq    #IOTD_SIZE-1,d0 ;clear the new IORequest (slowly)
  403.         move.l    a7,a0
  404. clearit     clr.b    (a0)+
  405.         dbra    d0,clearit
  406.         bsr    CREATEPORTE
  407.         beq.s    e_TDport
  408.         move.l    d0,MN_REPLYPORT(a7)
  409.         move.b    #NT_MESSAGE,LN_TYPE(a7)
  410.         lea    TrackName,a0
  411.         move.l    a7,a1
  412.         moveq    #1,d0
  413.         moveq    #0,d1
  414.         jsrlib    OpenDevice  ;[a0-name|d0=unit|a1-IO|d1-flags]
  415.         tst.l    d0
  416.         bne.s    e_TDopen
  417.         move.w    #CMD_READ,IO_COMMAND(a7) ;ETD!!
  418.         move.l    #512,IO_LENGTH(a7)
  419.         moveq    #9,d0
  420.         asl.l    d0,d2    ;shift d2 by d0
  421.         move.l    d2,IO_OFFSET(a7)
  422.         move.l    a3,IO_DATA(a7)
  423.         move.l    a7,a1
  424.         jsrlib    DoIO    ;[a1-IO]
  425.         move.l    MN_REPLYPORT(a7),a1
  426.         bsr    DELETEPORTE
  427.         move.b    IO_ERROR(a7),d0    ;cc's set
  428.         adda.l    #IOTD_SIZE,a7       ;cc's not
  429.         movem.l (a7)+,d2/a3/a6       ;cc's not
  430.         rts
  431. e_TDopen
  432. e_TDport    moveq    #-1,d0
  433.         rts
  434.  
  435. DOSName     dc.b 'dos.library',0
  436. Volume        dc.b 'df1:',0
  437. TrackName    dc.b 'trackdisk.device',0
  438.         dc.b 0,0
  439.         END
  440.  
  441.